package com.jd.controller;

import com.jd.bo.ShopcartBO;
import com.jd.pojo.Item;
import com.jd.pojo.ItemsImg;
import com.jd.pojo.ItemsParam;
import com.jd.pojo.ItemsSpec;
import com.jd.service.ItemService;
import com.jd.utils.JDJSONResult;
import com.jd.utils.PagedGridResult;
import com.jd.vo.CommentLevelCountsVO;
import com.jd.vo.ItemInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Api(value = "购物车接口controller",tags = {"购物车接口相关接口"})
@RestController
@RequestMapping("shopcart")
public class ShopcatController extends BaseController {

    @Autowired
    private ItemService itemService;



    @ApiOperation(value = "添加商品到购物车",notes = "添加商品到购物车",httpMethod = "POST")
    @PostMapping("/add")
    public JDJSONResult add(@ApiParam(name="itemId",value = "商品id",required = true)
                                     @RequestParam String userId,
                                     @RequestBody ShopcartBO shopcartBO,
                                     HttpServletRequest request, HttpServletResponse response){
        if(StringUtils.isBlank(userId)){
            return JDJSONResult.errorMsg("");
        }

        //TODO  前端用户在登录的情况下，添加商品到购物车，会同时在后端同步购物车到redis缓冲
        System.out.println(shopcartBO);

        return JDJSONResult.ok();
    }


    @ApiOperation(value = "从购物车中删除商品",notes = "从购物车中删除商品",httpMethod = "POST")
    @PostMapping("/del")
    public JDJSONResult del(@ApiParam(name="userId",value = "用户id",required = true)
                            @RequestParam String userId,
                            @ApiParam(name="itemSpecId",value = "规格id",required = true)
                            @RequestParam String itemSpecId,
                            HttpServletRequest request, HttpServletResponse response){
        if(StringUtils.isBlank(userId)||StringUtils.isBlank(itemSpecId)){
            return JDJSONResult.errorMsg("参数不能为空");
        }

        //TODO  前端用户在页面删除购物车中的商品数据，如果此时用户已经登录，则需要同步删除购物车中的数据
        return JDJSONResult.ok();
    }




}
